<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script src="js/jquery-1.11.3.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/page.js"></script>
<script type="text/javascript" src="js/common.js"></script>
<title>礼物信息</title>
</head>
<body>
    <jsp:include page="navigation.jsp"></jsp:include>
    <div class="container" style="margin-left: 190px; margin-bottom: 25px;">
        <div class="topbar-inner">
            <div class="myhead">
                <span class="crumb-name">礼物信息</span>
            </div>
        </div>
        <form id="pageForm" action="giftinfo" method="post">
            <c:if test="${ page != null}">
                <input type="hidden" value="${ page.pageCount }" id="pageCount" name="pageCount" />
                <input type="hidden" value="${ page.pageIndex }" id="pageIndex" name="pageIndex" />
            </c:if>
        </form>
        <div style="margin: 20px 20px 20px 20px; text-align: center;">
            <table class="table table-bordered table-hover table-striped">
                <thead>
                    <tr>
                        <th>礼物名称</th>
                        <th>图片地址</th>
                        <th>消费点数</th>
                        <th>消费时长</th>
                        <th width="10%">操作</th>
                    </tr>
                </thead>
                <tbody>
                    <c:forEach items="${ list }" var="l">
                        <tr>
                            <form id="trForm_${ l.id }" action="giftedit?id=${ l.id }" method="post" enctype="multipart/form-data">
                                <td><input type="text" class="form-control" id="giftname_${ l.id }" value="${ l.gift_name }" name="gift_name"></td>
                                <td><input type="file" class="btn" name="imgsfile" style="cursor: pointer;" id="uploadimage_${ l.id }" onchange="change('fileimage_${ l.id }','uploadimage_${ l.id }');" /> <c:if test="${empty l.pic }">
                                        <img src="images/defalut.png" name="pic" width=80px />
                                    </c:if> <c:if test="${not empty l.pic }">
                                        <img id="fileimage_${ l.id }" src="${ l.pic }" name="pic" width=80px />
                                    </c:if></td>
                                <td>${ l.point }</td>
                                <td><c:if test="${l.time == 0 }">普通礼物</c:if> <c:if test="${l.time  > 0 }">${l.time }秒</c:if></td>
                                <td width="10%"><a href="javascript:" onclick="toEdit(${ l.id })">修改</a></td>
                            </form>
                        </tr>
                    </c:forEach>
                </tbody>
            </table>
            <input type="hidden" value="${ page.pageCount }" id="pageCount" name="pageCount" /> <input type="hidden" value="${ page.pageIndex }" id="pageIndex" name="pageIndex" />
            <c:if test="${ page == null }">
                <div style="font-size: larger;">暂无数据</div>
            </c:if>
            <c:if test="${ page != null && page.pageCount > 1}">
                <ul id="pagination" class="pagination">

                </ul>
                <script type="text/javascript">
                    setPage(document.getElementById("pagination"),parseInt($("#pageCount").val()),parseInt($("#pageIndex").val()));
                </script>
            </c:if>
        </div>
    </div>
    <script type="text/javascript">
$(function() {
    $('.submenu_3_1').addClass('submenu_native');
});

function toEdit(id) {
    var giftname = $('#giftname_' + id).val().replace(/\s+/g, '');
    $('#giftname_' + id).val(giftname);
    if (giftname == '') {
        alert('礼物名称不能为空！');
        return false;
    }
    var pageIndex = $('#pageIndex').val();
    var html = '<input type="hidden" name="pageIndex" value="'+pageIndex+'" />';
    $('#trForm_' + id).append(html);
    $('#trForm_' + id).submit();
}
</script>
</body>
</html>